package com.yk.anima.controller;

import com.yk.anima.api.ProductsCatApi;
import com.yk.anima.pojo.ProductsCat;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.ProductsCatServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 09:17:19
 * @desc...
 */

@RequestMapping("/cat")
@RestController
public class ProductsCatController implements ProductsCatApi {


    @Autowired
    ProductsCatServlet productsCatServlet;

    /**
     * @param
     * @return java.util.List<com.yk.anima.pojo.Cat>
     * @Author xiaoKai
     * @Description 查询所有的猫类
     * @Date 18:18 2021/5/13
     */
    @Override
    @GetMapping("/findAll")
    public List<ProductsCat> findAll() {
        return productsCatServlet.findAll();
    }

    /**
     * @Author xiaoKai
     * @Description 根据Id查询具体猫
     * @Date 18:37 2021/5/13
     * @param id
     * @return com.yk.anima.pojo.ProductsCat
     */
    @Override
    @GetMapping("/findById/{id}")
    public ProductsCat findById(@PathVariable("id") int id) {
        return productsCatServlet.findById(id);
    }

    /**
     * @Author xiaoKai
     * @Description 添加猫
     * @Date 18:46 2021/5/13 
     * @param productsCat 
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ProductsCat productsCat) {
        return productsCatServlet.save(productsCat);
    }

    /**
     * @Author xiaoKai
     * @Description 对猫进行修改
     * @Date 18:57 2021/5/13 
     * @param id 
	 * @param productsCat 
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable int id, @RequestBody ProductsCat productsCat) {
        return productsCatServlet.update(id,productsCat);
    }

    /**
     * @Author xiaoKai
     * @Description 根据删除Id
     * @Date 19:26 2021/5/13
     * @param id
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @DeleteMapping("/deleteById/{id}")
    public ResponseResult delete(@PathVariable("id") int id) {
        return productsCatServlet.deleteById(id);
    }

    /**
     * @Author xiaoKai
     * @Description 分页操作
     * @Date 21:21 2021/5/13 
     * @param size 
	 * @param page 
	 * @param name 
     * @return com.yk.anima.response.QueryResponseResult
     */
    @Override
    @GetMapping("/findPage/{page}/{size}")
    public QueryResponseResult findByPage(@PathVariable("page") int page,
                                          @PathVariable("size") int size, String name) {

        return productsCatServlet.findPage(page,size,name);
    }
}
